package com.sacc.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.power.common.model.CommonResult;
import com.sacc.clients.BoxClient;
import com.sacc.mapper.ProductBoxMapper;
import com.sacc.pojo.ProductBox;
import com.sacc.service.ProductBoxService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author 滚~韬
 * @date 2022/5/25 15:42
 */
@Service
public class ProductBoxServiceImpl implements ProductBoxService {
    @Autowired
    private ProductBoxMapper productBoxMapper;
    @Autowired
    private BoxClient boxClient;
    //添加对应产品的蜂箱id
    @Override
    public CommonResult Add(Integer productId,Integer boxId) {
        try{
            if(productBoxMapper.selectCount(new QueryWrapper<ProductBox>().eq("product_id",productId))>0){
                return new CommonResult(false,"插入失败，已经有了");
            }else {
                ProductBox productBox = new ProductBox();
                productBox.setProductId(productId);
                productBox.setBoxId(boxId);
                productBoxMapper.insert(productBox);
                boxClient.AddProductid(productId,boxId);
                return new CommonResult(true,"插入成功",productBox);
            }
        }catch (Exception e){
            return new CommonResult(false,"遇到问题"+e.toString());
        }
    }
    //得到对应产品的蜂箱id
    @Override
    public CommonResult Get(Integer productId) {
        return new CommonResult(true,"成功获取",productBoxMapper.selectById(productId));
    }
}
